<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

<body class="gray-bg">

<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 校区
                </div>
                <div class="box-tools pull-right">
<!--                    <a type="button" class="btn btn-box-tool menuItem" href="#" onclick="dept()" title="校区"><i class="fa fa-edit"></i></a>-->
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新校区"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
</div>

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="user-form">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <input type="hidden" id="createBy" name="createBy">
                <div class="select-list">
                    <ul>
                        <li>
                            文件名：<input type="text" name="fileName"/>
                        </li>
                        <li class="select-time">
                            <label>上传时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="beginTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
                        </li>
                        <li style="width: 100%;text-align: center">
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()"
               shiro:hasPermission="teach:teachPersonalDocuments:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="teach:teachPersonalDocuments:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="teach:teachPersonalDocuments:remove">
                <i class="fa fa-remove"></i> 删除
            </a>

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/ajax/libs/ajaxfile/ajaxupload.js}"></script>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('teach:teachPersonalDocuments:edit')}]];
    var removeFlag = [[${@permission.hasPermi('teach:teachPersonalDocuments:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "teach/teachPersonalDocuments";
    // var queryDeptTree = ctx + "/system/user/treeData";

    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        queryUserList();
        queryDeptTree();
    });
    function queryUserList(){
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "个人文件",
            search: false,
            showExport: false,
            sortable:false,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'fileName',
                    title: '文件名'
                },
                {
                    field: 'originalName',
                    title: '原名'
                },
                {
                    field: 'fileSuffix',
                    title: '文件后缀名'
                },
                {
                    title: '文件预览',
                    field: 'fileUrl',
                    formatter:function(value,row,index){
                        var s='';
                        if (/^(.jpg|.jpeg|.png|.gif|)$/.test(row.fileSuffix.toLowerCase())){
                            s= '<a class = "view"  href="javascript:void(0)"><img style="width:30;height:30px;"  src="'+row.fileUrl+'" /></a>';
                        }else {
                            s=  row.fileUrl;
                        }
                        return s;
                    },
                    events: 'operateEvents',
                    width: '175px'
                },
                {
                    field: 'fileSize',
                    title: '文件大小'
                },
                {
                    field: 'downloadTimes',
                    title: '下载次数'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'createTime',
                    title: '上传时间'
                },
                {
                    field: 'createBy',
                    title: '上传人'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    field: 'updateBy',
                    title: '更新人'
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '100px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if(/^(.jpg|.jpeg|.png|.gif|)$/.test(row.fileSuffix.toLowerCase())){
                            actions.push('<a class="btn btn-info btn-xs ' + '" href="#" onclick="preview(\'' + row.id + '\')"><i class="fa fa-search"></i>预览</a> ');
                        }
                        actions.push('<a class="btn btn-info btn-xs ' + '" href="#" onclick="downloadFile(\'' + row.id + '\')"><i class="fa fa-download"></i>下载</a> ');
                        return $.table.dropdownToggle(actions.join(''));
                    }
                }]
        };
        $.table.init(options);
    };

    function downloadFile(id){
        window.location.href = prefix + "/downloadFile?id=" + id;
    }

    /* 个人文件预览 */
    function preview(id) {
        var url = prefix + '/preview/' + id;
        $.modal.open("预览图片", url, '800', '800');
    }

    function queryDeptTree()
    {
        var url = ctx + "system/user/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            debugger;
            if ("user" == treeNode.dataType){
                $("#createBy").val(treeNode.id);
                $("#deptId").val("");
                $("#parentId").val("");
            }else {
                $("#createBy").val("");
                $("#deptId").val(treeNode.id);
                $("#parentId").val(treeNode.pId);
            }
            $.table.search();
        }
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });
    $('#btnRefresh').click(function() {
        queryDeptTree();
    });
    /* 用户管理-部门 */
    // function dept() {
    //     var url = ctx + "system/dept";
    //     createMenuItem(url, "校区");
    // }


</script>
</body>
</html>